const int nLIGHTS = 9;
const float kFalloffMult = 0.04;
const float kFalloffExp = 0.4;

uniform sampler2D texture;
uniform vec3 lightPos[nLIGHTS];

varying float kDiffuse[nLIGHTS];
varying float kFalloff[nLIGHTS];

vec3 getECLightPosition(vec3 lightPosN) {
	vec4 posLightN4 = vec4(lightPosN, 1.0);
	vec3 posLightN_EC = (gl_ModelViewMatrix * posLightN4).xyz;
	return posLightN_EC;
}

float vlengthPow(vec3 vc, float exponent) {
	return pow(vc.x * vc.x + vc.y * vc.y + vc.z * vc.z, exponent);
}

void main() {
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;
    
    vec3 nvecNorm = normalize(gl_NormalMatrix * gl_Normal);
    vec3 posVertEC = (gl_ModelViewMatrix * gl_Vertex).xyz;
    
    vec3 posLightEC[nLIGHTS];
    vec3 vecVtoL[nLIGHTS];
    vec3 nvecLight[nLIGHTS];
    float nDotL[nLIGHTS];
    
    for (int i = 0; i < nLIGHTS; i++) {
    	
    	posLightEC[i] = getECLightPosition(lightPos[i]);
    	vecVtoL[i] = posLightEC[i] - posVertEC;
    	nvecLight[i] = normalize(vecVtoL[i]);
    	nDotL[i] = dot(nvecLight[i], nvecNorm);
    	kDiffuse[i] = max(nDotL[i], 0.0);
    	
    	kFalloff[i] = 1.0 - kFalloffMult * vlengthPow(vecVtoL[i], kFalloffExp);
    	
    }
    
    
}

    //posLightEC[0] = getECLightPosition(lightPos[0]);
    //vecLight[0] = normalize(posLightEC[0] - posVert);
    //nDotL[0] = dot(vecNorm, vecLight[0]);
    //kDiffuse[0] = max(nDotL[0], 0.0);
